#ifndef MYDB_H
#define MYDB_H

#include <QObject>
#include <QSqlDatabase>
#include <QMetaType>
#include "CommonType.h"

class MyDb : public QObject
{
    Q_OBJECT

public:
    static MyDb * instance();
    ~MyDb();
    static QString getField(QSqlQuery query, QString colName);
    QSqlQuery getMeter(QString zcbh, int iMeterType);
    int getMeterID(int iMeterType, QString zcbh);
    bool setMeter(int iMeterType, QString ccbh, QString sjdw,
                  QString xh, QString volt, QString amp,
                  QString djY, QString djW, QString sccj,
                  QString xx, int sx, QString start, QString qiandong);

    bool SaveWcData(int iMeterType,QString zcbh,
                  float f32_UaRMS,float f32_UbRMS,float f32_UcRMS,
                  float f32_IaRMS,float f32_IbRMS,float f32_IcRMS,
                  float f32_Pa,float f32_Pb,float f32_Pc,
                  float f32_Qa,float f32_Qb,float f32_Qc,
                  float f32_Ptot,float f32_Qtot,float f32_Freq,
                  float f32_ErrDisplay1,float f32_ErrDisplay2);

    QSqlQuery getReportData(int iMeterType, QString strZCBH, QString strDate);
    QSqlQuery getReportData(int id);

    bool deleteReportData(int id);

    QVariant getSystemConfig(QString key, QVariant defValue);
    QStringList SelectGroup(QString login_name);

    bool UpdateGroup(QString login_name,QStringList sl);    
    bool UpdateMember(int id,QString login_name,QString group,QString phone, QString name,QString sex,QString birthday,QString address,QString other);
    bool DeleteMember(int id);

    bool UpdateQiDong(int main_id, QString qiDong, QString qianDong);
    QSqlQuery getReportJbwc(int id, QString group_name);
    bool deleteJbwc(int main_id);
    bool InsertJbwc(int main_id,QString xm,QString glys,QString amp,double wcyz,double wchz,double wcx,QString group_name);
    QSqlQuery getReportBzpc(int id);
    bool deleteBzpc(int main_id);
    bool InsertBzpc(int main_id,double pcyz1,double pchz1,double pcyz2,double pchz2,double wcx,QString detail1,QString detail2);

    QString getFactor(int lcV, int lcA, int phase, int iType);
    bool setFactor(int lcV, int lcA, int phase, int iType, QString value);

    QSqlQuery getJbwcSetting(QString strDj);
    QSqlQuery getBzpcSetting(QString strDj);
private:
    MyDb();
    bool initDb();
    bool createMeterTable();
    bool createWcDataTable();
    bool createFactorTable();

    static MyDb * sqlitedb;

signals:
    void szSettingValueChanged();
    void lvSettingValueChanged();
    void sz61850SettingValueChanged();
    void cameraValueChanged();

public slots:

};

#endif // CONFIG_H
